import {
    _decorator, BoxCollider2D,
    CircleCollider2D, Component,
    Contact2DType, Node, RigidBody2D,
    Collider2D,
    IPhysics2DContact
} from 'cc';

const { ccclass, property } = _decorator;

@ccclass('PlayerControl')
export class PlayerControl extends Component {

    @property({ type: Number, displayName: "磁力", tooltip: "磁力" })
    magnetic: number = 10;

    @property({ type: Number, displayName: "磁力范围", tooltip: "磁力范围,在此范围内的铁物体会收到吸引" })
    magneticRange: number = 500;

    @property(CircleCollider2D)
    magneticForceBox: CircleCollider2D = null!;


    start() {
       this.magneticForceBox.radius = this.magneticRange;
        console.log(this.magneticForceBox.sensor);
        this.magneticForceBox.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
    }

    show() {

    }

    update(deltaTime: number) {

    }
    // 为参数添加类型注解以解决隐式any类型问题
    onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        // if (otherCollider.tag === -1) {
        //     return;
        // }
        console.log(selfCollider);
        console.log(otherCollider.tag);
        console.log(contact);
    }
}


